<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="88px">
                                      <el-form-item label="会员编号" prop="customerId">
        <el-input
          v-model="queryParams.customerId"
          placeholder="请输入会员编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

       <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="未支付" value="1" />
          <el-option label="已支付" value="2" />
        </el-select>
      </el-form-item>
        <el-form-item label="外部订单号" prop="outTradeNo">
        <el-input
          v-model="queryParams.outTradeNo"
          placeholder="请输入外部订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
          <el-form-item label="内容标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
         <el-form-item label="类别" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类别" clearable size="small">
          <el-option label="房屋信息" value="1" />
          <el-option label="农林牧渔" value="2" />
          <el-option label="物品信息" value="3" />
           <el-option label="本地推广" value="4" />
          <el-option label="求购信息" value="5" />
           <el-option label="招聘信息" value="6" />

           <el-option label="生意转让" value="8" />
           <el-option label="车况信息" value="10" />
        </el-select>
      </el-form-item>

         <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

          <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['tc:TcOrder:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['tc:TcOrder:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="TcOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
                  <el-table-column label="编号" align="center" prop="id" />
                   <el-table-column label="标题" align="center" prop="title" />
                    <el-table-column label="类别" align="center" prop="type" />
                  <el-table-column label="会员编号" align="center" prop="customerId" />
                  <el-table-column label="支付金额" align="center" prop="payAmount" />
                  <el-table-column label="状态" align="center" prop="status"  :formatter="statusFormat"/>
                  <el-table-column label="外部订单号" align="center" prop="outTradeNo" />
                    <el-table-column label="订单号" align="center" prop="orderNo" />
                  <el-table-column label="信息发布费" align="center" prop="publishAmout" />
                  <el-table-column label="置顶费" align="center" prop="topAmount" />
                  <el-table-column label="置顶天数" align="center" prop="topDay" />

                  <el-table-column label="信息折扣" align="center" prop="publishSmsAmout" />
                  <el-table-column label="会员等级" align="center" prop="memberLevel" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['tc:TcOrder:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                                                            <el-form-item label="当前折扣" prop="customerId">
          <el-input v-model="form.customerId" placeholder="请输入当前折扣" />
        </el-form-item>
                                                                    <el-form-item label="支付金额" prop="payAmount">
          <el-input v-model="form.payAmount" placeholder="请输入支付金额" />
        </el-form-item>
                                                                    <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
                                                                    <el-form-item label="外部订单号" prop="outTradeNo">
          <el-input v-model="form.outTradeNo" placeholder="请输入外部订单号" />
        </el-form-item>
                                                                                    <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入标题" />
        </el-form-item>
                                                                    <el-form-item label="类别">
          <el-select v-model="form.type" placeholder="请选择类别">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
                                                                    <el-form-item label="信息发布费" prop="publishAmout">
          <el-input v-model="form.publishAmout" placeholder="请输入信息发布费" />
        </el-form-item>
                                                                    <el-form-item label="置顶费" prop="topAmount">
          <el-input v-model="form.topAmount" placeholder="请输入置顶费" />
        </el-form-item>
                                                                    <el-form-item label="置顶天数" prop="topDay">
          <el-input v-model="form.topDay" placeholder="请输入置顶天数" />
        </el-form-item>
                                                                    <el-form-item label="订单号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单号" />
        </el-form-item>
                                                                    <el-form-item label="信息折扣" prop="publishSmsAmout">
          <el-input v-model="form.publishSmsAmout" placeholder="请输入信息折扣" />
        </el-form-item>
                                                                    <el-form-item label="当前折扣" prop="memberLevel">
          <el-input v-model="form.memberLevel" placeholder="请输入当前折扣" />
        </el-form-item>
                  </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTcOrder, getTcOrder, delTcOrder, addTcOrder, updateTcOrder, exportTcOrder } from "@/api/tc/TcOrder";

export default {
  name: "TcOrder",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 订单表格数据
      TcOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
                                                                                                                                                                              // 查询参数
      queryParams: {
        pageNum: 0,
        pageSize: 10,
                customerId: undefined,
                payAmount: undefined,
                status: undefined,
                outTradeNo: undefined,
                    title: undefined,
                type: undefined,
                publishAmout: undefined,
                topAmount: undefined,
                topDay: undefined,
                orderNo: undefined,
                publishSmsAmout: undefined,
                memberLevel: undefined
          },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
                                                              }
    };
  },
  created() {
    this.getList();
                                                          },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listTcOrder(this.queryParams).then(response => {
        this.TcOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

            statusFormat(row, column) {
                                             if(row.status=='1'){
                                               return '未支付';
                                             }
                                              return '已支付';
                                            },
        // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
            id: undefined,
                customerId: undefined,
                payAmount: undefined,
                status: "0",
                outTradeNo: undefined,
                createTime: undefined,
                title: undefined,
                type: undefined,
                publishAmout: undefined,
                topAmount: undefined,
                topDay: undefined,
                orderNo: undefined,
                publishSmsAmout: undefined,
                memberLevel: undefined
          };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 0;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTcOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateTcOrder(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addTcOrder(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除订单编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTcOrder(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有订单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTcOrder(queryParams);
        }).then(response => {
          this.download(response.data);
        }).catch(function() {});
    }
  }
};
</script>
